package com.example.saiweisi.controller.systemAdminController;

import com.example.saiweisi.common.Result;
import com.example.saiweisi.controller.request.CaipinRequest;
import com.example.saiweisi.controller.request.DiancanRequest;
import com.example.saiweisi.controller.request.OrderRequest;
import com.example.saiweisi.service.impl.userService.DiancanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/diancan")
@RestController
@CrossOrigin
@Slf4j
public class DianCanController {

    @Autowired
    DiancanService diancanService;
    //提交订单
    @PostMapping("/submit/{userId}/{sum}")
    public Result submitOrder(@PathVariable Integer userId,@PathVariable Double sum, @RequestBody List<DiancanRequest> diancanRequest) {
        diancanService.submit(userId,sum,diancanRequest);
        return Result.success();
    }
    @PostMapping("/submit/{sum}")
    public Result submitOrderNouser(@PathVariable Double sum, @RequestBody List<DiancanRequest> diancanRequest) {
        diancanService.submit(null,sum,diancanRequest);
        return Result.success();
    }

    @PostMapping("/update/{orderId}/{sum}")
    public Result updateOrder(@PathVariable Integer orderId,@PathVariable Double sum, @RequestBody List<DiancanRequest> diancanRequest) {
        diancanService.update(orderId,sum,diancanRequest);
        return Result.success();
    }
}
